package org.grow.mvcpractise.filter;



import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

@Service
public class FirstFilter implements Filter {

    private AtomicInteger countTotal = new AtomicInteger(0);

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        System.out.println("================我是　一楼");

//        countTotal+=1;
//        countTotal = countTotal+1;

        int i = countTotal.incrementAndGet();
//        String requestURI = httpServletRequest.getRequestURI();
//        System.out.println("---request URI"+requestURI);
//        if (requestURI.contains("/personAjax")){
//            return;
//        }
//        web Servlet Filter ; spring Controller Intercepter


        httpServletRequest.setAttribute("password","1234567");



        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("================我是　一楼　倒序 目前服务器访问总数　"+i);

    }
}
